import time
import pytest
import allure
import TestCase

from Base.InitDriver import init_driver
from Page.CommonPage import CommonPage
from Utils.XiaoMaUtils import XiaoMaUtils


@allure.feature('TestCase_07: 按照每隔6个月的时间间隔进行排序')
@allure.issue(
    'https://www.tapd.cn/54441127/sparrow/tcase/view/1154441127001066084?url_cache_key=5b07a59231afaf505fb7dc2f4205dfae')
class TestCaseService07:
    def setup_class(self):
        self.driver = init_driver()
        # 实例化页面
        # 桌面
        self.launcher_index_page = CommonPage(self.driver).get_launcher_index_page()
        self.launcher_app_list_page = CommonPage(self.driver).get_launcher_app_list_page()
        # 车服务
        self.service_index_page = CommonPage(self.driver).get_service_index_page()
        self.service_city_page = CommonPage(self.driver).get_service_city_page()
        self.service_customer_hotline_page = CommonPage(self.driver).get_service_customer_hotline_page()
        self.service_driving_score_page = CommonPage(self.driver).get_service_driving_score_page()
        self.service_health_house_keeper_page = CommonPage(self.driver).get_service_health_house_keeper_page()
        self.service_maintenance_plan_page = CommonPage(self.driver).get_service_maintenance_page()
        self.service_my_reservation_page = CommonPage(self.driver).get_service_my_reservation_page()
        self.service_new_operating_page = CommonPage(self.driver).get_service_new_operating_page()
        self.service_reservation_page = CommonPage(self.driver).get_service_reservation_page()
        self.service_store_select_page = CommonPage(self.driver).get_service_store_select_page()
        self.service_time_page = CommonPage(self.driver).get_service_time_page()


    def teardown_class(self):
        XiaoMaUtils.close_app('service')
        # XiaoMaUtils.clear_data('personal')
        self.driver.quit()

    @allure.story('step1:点击应用页,进入车辆管家')
    @pytest.mark.run(order=71)
    def test_service_07_1_click_list(self):
        try:
            self.launcher_index_page.click_app_list()
            self.launcher_app_list_page.click_appname(TestCase.SERVICE)
            time.sleep(5)
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step2: 点击养车计划,进入养车计划页面")
    @pytest.mark.run(order=72)
    def test_service_07_2_click_service(self):
        try:
            self.service_index_page.click_list_category("养车计划")
            text1 = self.service_maintenance_plan_page.get_ele_text(
                self.service_maintenance_plan_page.get_mileage_time())
            text2 = self.service_maintenance_plan_page.get_ele_text(
                self.service_maintenance_plan_page.get_mileage_time(index=2))
            text3 = self.service_maintenance_plan_page.get_ele_text(
                self.service_maintenance_plan_page.get_mileage_time(index=3))
            a = int(text1[7:9])
            b = int(text2[7:9])
            c = int(text3[7:9])
            # print(a, b, c)
            if b == a + 6 and c == b + 6:
                print("养车计划按照6个月排序正确")
            else:
                print("养车计划排序错误")
            time.sleep(5)
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)


if __name__ == 'main__':
    # pass
    pytest.main("-s testcase_service_07.py")
